3f05631dMY7PMkwSY7zBFelGJ8goVg tools/control/src/org/xenoserver/cmdline/ParsePhysicalList.java
3f05631dYDFXv6mwNFAgz3ta9kShJA tools/control/src/org/xenoserver/cmdline/ParsePhysicalRevoke.java
3f0bdfabfXM4tMbvmV06di5U-5FfqA tools/control/src/org/xenoserver/cmdline/ParseVbdCreate.java
-3f0bf89f_DkClyexDd4EDwinZJG83A tools/control/src/org/xenoserver/cmdline/ParseVbdDelete.java
-3f0bf89fvzPQqcHBq1xA0XlFiO8tLA tools/control/src/org/xenoserver/cmdline/ParseVbdFlush.java
3f0bec93F_VDIcn9oeXwJYwydX20kg tools/control/src/org/xenoserver/cmdline/ParseVbdShow.java
3f098761TRsbDk9woUM846Q6_F7EmA tools/control/src/org/xenoserver/cmdline/ParseVdCreate.java
3f099009pmH9MFkRYwP2V1DfsqEwdg tools/control/src/org/xenoserver/cmdline/ParseVdDelete.java
3f05631eGWxq7bojQbMa-tGxsENIhw tools/control/src/org/xenoserver/control/CommandPhysicalRevoke.java
3f0bdfab88VYiD26FXCDmmAAGJ8zWA tools/control/src/org/xenoserver/control/CommandVbdCreate.java
3f0bdfabI14M5_odjCIwQbXCdauReA tools/control/src/org/xenoserver/control/CommandVbdCreatePhysical.java
-3f0bf89fcVy1cFU18hPVXkFMMLHLug tools/control/src/org/xenoserver/control/CommandVbdDelete.java
-3f0bf8a0aRDXkIGy3liS1oKXIQpeyA tools/control/src/org/xenoserver/control/CommandVbdFlush.java
+3f0d4a70B132OMLyoUBFJAfNCATCww tools/control/src/org/xenoserver/control/CommandVbdList.java
3f098761c5-idlmf9vWEMOlDw0VCHg tools/control/src/org/xenoserver/control/CommandVdCreate.java
3f0990096KcyQw77qJmjTu941smS8A tools/control/src/org/xenoserver/control/CommandVdDelete.java
3f0990093VJUL7QjxGigR5GPXf_Fkw tools/control/src/org/xenoserver/control/CommandVdRefresh.java
};
private static final CommandParser vbdcommands[] =
{ new ParseVbdCreate(),
- new ParseVbdDelete(),
- new ParseVbdFlush(),
new ParseVbdShow()
};
private static final CommandParser commands[] =
+++ /dev/null
-package org.xenoserver.cmdline;
-
-import java.util.LinkedList;
-
-import org.xenoserver.control.CommandFailedException;
-import org.xenoserver.control.CommandVbdDelete;
-import org.xenoserver.control.Defaults;
-
-public class ParseVbdDelete extends CommandParser {
- public void parse(Defaults d, LinkedList args)
- throws ParseFailedException, CommandFailedException {
- int domain_id = getIntParameter(args, 'n', 0);
- int vbd_num = getIntParameter(args, 'v', -1);
-
- if (domain_id == 0) {
- throw new ParseFailedException("Expected -n<domain_id>");
- }
- if (vbd_num == -1) {
- throw new ParseFailedException("Expected -v<vbd_num>");
- }
- loadState();
- String output = new CommandVbdDelete(domain_id, vbd_num).execute();
- if (output != null) {
- System.out.println(output);
- }
- saveState();
- }
-
- public String getName() {
- return "delete";
- }
-
- public String getUsage() {
- return "-n<domain> -v<vbd>";
- }
-
- public String getHelpText() {
- return "Deletes the specified virtual block device from the specified domain.";
- }
-
-}
+++ /dev/null
-package org.xenoserver.cmdline;
-
-import java.util.LinkedList;
-
-import org.xenoserver.control.CommandFailedException;
-import org.xenoserver.control.CommandVbdFlush;
-import org.xenoserver.control.Defaults;
-
-public class ParseVbdFlush extends CommandParser {
- public void parse(Defaults d, LinkedList args)
- throws ParseFailedException, CommandFailedException {
- loadState();
- String output = new CommandVbdFlush().execute();
- if (output != null) {
- System.out.println(output);
- }
- saveState();
- }
-
- public String getName() {
- return "flush";
- }
-
- public String getUsage() {
- return "";
- }
-
- public String getHelpText() {
- return "Delete all virtual block devices";
- }
-}
package org.xenoserver.cmdline;
-import java.util.Iterator;
import java.util.LinkedList;
import org.xenoserver.control.CommandFailedException;
+import org.xenoserver.control.CommandVbdList;
import org.xenoserver.control.Defaults;
import org.xenoserver.control.Library;
import org.xenoserver.control.VirtualBlockDevice;
-import org.xenoserver.control.VirtualDiskManager;
public class ParseVbdShow extends CommandParser {
public void parse(Defaults d, LinkedList args)
throws ParseFailedException, CommandFailedException {
loadState();
- Iterator i = VirtualDiskManager.IT.getVirtualBlockDevices();
+ CommandVbdList list = new CommandVbdList();
+ list.execute();
+ VirtualBlockDevice[] vbds = list.vbds();
System.out.println("key dom vbd mode");
- while (i.hasNext()) {
- VirtualBlockDevice vbd = (VirtualBlockDevice) i.next();
- System.out.println( vbd.getVirtualDisk().getKey()
+ for (int i=0; i<vbds.length; i++) {
+ System.out.println( vbds[i].getVirtualDisk().getKey()
+ " "
- + Library.format(vbd.getDomain(), 3, false)
+ + Library.format(vbds[i].getDomain(), 3, false)
+ " "
- + Library.format(vbd.getVbdNum(), 3, false)
+ + Library.format(vbds[i].getVbdNum(), 3, false)
+ " "
- + vbd.getMode().toString());
+ + vbds[i].getMode().toString());
}
}
public void parse(Defaults d, LinkedList args)
throws ParseFailedException, CommandFailedException {
String vd_key = getStringParameter(args, 'k', "");
+ boolean force = getFlagParameter(args,'f');
if (vd_key.equals("")) {
throw new ParseFailedException("Expected -k<key>");
}
loadState();
- String output = new CommandVdDelete(vd_key).execute();
+ String output = new CommandVdDelete(vd_key,force).execute();
if (output != null) {
System.out.println(output);
}
}
public String getUsage() {
- return "-k<key>";
+ return "-k<key> [-f]";
}
public String getHelpText() {
- return "Deletes the virtual disk with the specified key.";
+ return "Deletes the virtual disk with the specified key. -f forces deletion even if the disk is in use.";
}
}
}
VirtualBlockDevice vbd =
- VirtualDiskManager.IT.createVirtualBlockDevice(
+ new VirtualBlockDevice(
vd,
domain_id,
vbd_num,
+++ /dev/null
-package org.xenoserver.control;
-
-/**
- * Delete a virtual block device. Note that this does not update anything inside
- * Xen, and therefore should only be done if you are certain that the domain has
- * either not been started, or has been destroyed, or you are sure it will not
- * try to access the VBD again. Since the mapping is not removed in Xen, any
- * subsequent changes to the underlying virtual disk will affect the domain,
- * probably adversely.
- */
-public class CommandVbdDelete extends Command {
- /** Domain id to delete from */
- private int domain_id;
- /** VBD number to delete */
- private int vbd_num;
-
- /**
- * Constructor for CommandVbdDelete.
- * @param domain_id Domain ID to delete from
- * @param vbd_num VBD number to delete
- */
- public CommandVbdDelete(int domain_id, int vbd_num) {
- this.domain_id = domain_id;
- this.vbd_num = vbd_num;
- }
-
- /**
- * @see org.xenoserver.control.Command#execute()
- */
- public String execute() throws CommandFailedException {
- if (VirtualDiskManager
- .IT
- .deleteVirtualBlockDevice(domain_id, vbd_num)) {
- return "Deleted VBD " + vbd_num + " from domain " + domain_id;
- } else {
- throw new CommandFailedException(
- "No such virtual block device "
- + vbd_num
- + " in domain "
- + domain_id);
- }
- }
-}
+++ /dev/null
-package org.xenoserver.control;
-
-/**
- * Flush (delete) all virtual block devices.
- */
-public class CommandVbdFlush extends Command {
- /**
- * @see org.xenoserver.control.Command#execute()
- */
- public String execute() throws CommandFailedException {
- VirtualDiskManager.IT.flushVirtualBlockDevices();
- return "Flushed virtual block devices";
- }
-}
--- /dev/null
+package org.xenoserver.control;
+
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.StringTokenizer;
+import java.util.Vector;
+
+public class CommandVbdList extends Command {
+ /** Array of virtual block devices returned */
+ private VirtualBlockDevice[] array;
+
+ public String execute() throws CommandFailedException {
+ Vector v = new Vector();
+ BufferedReader in;
+ String line;
+
+ try {
+ in = new BufferedReader(new FileReader("/proc/xeno/dom0/vhd"));
+ line = in.readLine();
+ while (line != null) {
+ int domain = -1;
+ int vbdnum = -1;
+ String key = "";
+ Mode mode = Mode.READ_ONLY;
+
+ StringTokenizer st = new StringTokenizer(line);
+ if (st.hasMoreTokens()) {
+ domain = Integer.parseInt(st.nextToken());
+ }
+ if (st.hasMoreTokens()) {
+ vbdnum = Integer.parseInt(st.nextToken());
+ }
+ if (st.hasMoreTokens()) {
+ key = st.nextToken();
+ }
+ if (st.hasMoreTokens()) {
+ if (Integer.parseInt(st.nextToken()) == 2) {
+ mode = Mode.READ_WRITE;
+ }
+ }
+
+ VirtualDisk vd = VirtualDiskManager.IT.getVirtualDisk(key);
+ if (vd == null) {
+ throw new CommandFailedException(
+ "Key " + key + " has no matching virtual disk");
+ }
+ VirtualBlockDevice vbd =
+ new VirtualBlockDevice(vd, domain, vbdnum, mode);
+ v.add(vbd);
+
+ line = in.readLine();
+ }
+ } catch (IOException e) {
+ throw new CommandFailedException("Could not read VBD file", e);
+ }
+
+ array = new VirtualBlockDevice[v.size()];
+ v.toArray(array);
+ return null;
+ }
+
+ public VirtualBlockDevice[] vbds() {
+ return array;
+ }
+}
public class CommandVdDelete extends Command {
/** Key of disk to delete. */
private String key;
+ /** Force deletion? */
+ private boolean force;
/**
* Constructor for CommandVdDelete.
* @param key The key of the disk to delete.
*/
- public CommandVdDelete(String key) {
+ public CommandVdDelete(String key,boolean force) {
this.key = key;
+ this.force = force;
}
/**
throw new CommandFailedException(
"Virtual disk " + key + " does not exist");
}
+ if ( !force ) {
+ CommandVbdList list = new CommandVbdList();
+ list.execute();
+ VirtualBlockDevice[] vbds = list.vbds();
+ for (int i=0;i<vbds.length;i++) {
+ if (vbds[i].getVirtualDisk().getKey().equals(key)) {
+ throw new CommandFailedException("Virtual disk " + key + " is in use.");
+ }
+ }
+ }
VirtualDiskManager.IT.deleteVirtualDisk(key);
return "Deleted virtual disk " + key;
package org.xenoserver.control;
-import java.io.PrintWriter;
-
/**
* A virtual block device; a mapping from a domain-specific number to a virtual
* disk with associated access mode.
this.mode = mode;
}
- /**
- * Dump the virtual block device as XML.
- * @param out The writer to dump to.
- */
- void dumpAsXML(PrintWriter out) {
- out.println(" <virtual_block_device>");
- out.println(" <key>" + vd.getKey() + "</key>");
- out.println(" <domain>" + domain + "</domain>");
- out.println(" <vbdnum>" + vbdNum + "</vbdnum>");
- out.println(" <mode>" + mode + "</mode>");
- out.println(" </virtual_block_device>");
- }
-
/**
* @return This device's virtual disk.
*/
private VirtualDisk freeDisk;
/** The map of keys to virtual disks. */
private LinkedHashMap virtualDisks = new LinkedHashMap(100);
- /** The map of (domain,vbdnum) to virtual block devices. */
- private LinkedHashMap virtualBlockDevices = new LinkedHashMap(100);
/**
* VDM constructor, private as it's a singleton.
}
}
- /**
- * Create a new virtual block device.
- * @param vd The virtual disk to expose.
- * @param domain The domain to create the device for.
- * @param vbdNum The block device number to use.
- * @param mode The mode to create the device with.
- * @return The newly created virtual block device.
- */
- VirtualBlockDevice createVirtualBlockDevice(
- VirtualDisk vd,
- int domain,
- int vbdNum,
- Mode mode) {
- VirtualBlockDevice vbd =
- new VirtualBlockDevice(vd, domain, vbdNum, mode);
-
- insertVirtualBlockDevice(vbd);
-
- return vbd;
- }
-
- /**
- * Delete a virtual block device.
- * @param domain Domain owning the device.
- * @param vbdNum The vbd number within the domain.
- * @return true if the VBD was deleted, false if it does not exist.
- */
- boolean deleteVirtualBlockDevice(int domain, int vbdNum) {
- Object hash = hashVBD(domain, vbdNum);
- return virtualBlockDevices.remove(hash) != null;
- }
-
- /**
- * Flush all virtual block devices.
- */
- void flushVirtualBlockDevices() {
- /* isn't automatic garbage collection wonderful? */
- virtualBlockDevices = new LinkedHashMap(100);
- }
-
/**
* Insert a new virtual disk into the map.
* @param vd The disk to insert.
virtualDisks.put(vd.getKey(), vd);
}
- /**
- * Insert a new virtual block device into the map.
- * @param vbd The device to insert.
- */
- void insertVirtualBlockDevice(VirtualBlockDevice vbd) {
- Object hash = hashVBD(vbd.getDomain(), vbd.getVbdNum());
- virtualBlockDevices.put(hash, vbd);
- }
-
/**
* Hash a virtual block device.
* @param domain The VBD's domain.
vd.dumpAsXML(out);
}
out.println("</virtual_disks>");
- out.println("<virtual_block_devices>");
- i = virtualBlockDevices.values().iterator();
- while (i.hasNext()) {
- VirtualBlockDevice vbd = (VirtualBlockDevice) i.next();
- vbd.dumpAsXML(out);
- }
-
- out.println("</virtual_block_devices>");
}
/**
return freeDisk;
}
- /**
- * @return An iterator over the virtual block devices.
- */
- public Iterator getVirtualBlockDevices() {
- return virtualBlockDevices.values().iterator();
- }
-
/**
* @return An iterator over the virtual disks.
*/
+ "]");
}
}
-
- /* parse virtual block devices */
- parseVirtualBlockDevices(
- vdm,
- document.getElementsByTagName("virtual_block_device"));
-
- return;
}
/**
pm.addXenoPartition(partition);
}
}
-
- /**
- * Parse a list of virtual block device nodes.
- * @param vdm The VirtualDiskManager to configure.
- * @param nl The node list.
- */
- private static void parseVirtualBlockDevices(
- VirtualDiskManager vdm,
- NodeList nl) {
- for (int loop = 0; loop < nl.getLength(); loop++) {
- Node node = nl.item(loop);
- Mode mode;
-
- if (XMLHelper
- .getText(XMLHelper.getSubNode("mode", node))
- .equals("rw")) {
- mode = Mode.READ_WRITE;
- } else {
- mode = Mode.READ_ONLY;
- }
-
- vdm.createVirtualBlockDevice(
- vdm.getVirtualDisk(
- XMLHelper.getText(XMLHelper.getSubNode("key", node))),
- Integer.parseInt(
- XMLHelper.getText(XMLHelper.getSubNode("domain", node))),
- Integer.parseInt(
- XMLHelper.getText(XMLHelper.getSubNode("vbdnum", node))),
- mode);
- }
- }
}